package com.ruoyi.erp.goodpath.service.impl;

import com.ruoyi.erp.goodpath.domain.DeliveryRouteTab;
import com.ruoyi.erp.goodpath.mapper.GoodPathMapper;
import com.ruoyi.erp.goodpath.service.GoodPathService;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @version 2017.1.1
 * @Auther Du Ruifang @萌えキュンキュン
 * @Date 2020/12/21 09:39
 * @description 该类的作用
 */
@Service
public class GoodPathServiceImpl implements GoodPathService {
    @Resource
    private GoodPathMapper goodPathMapper;
    @Override
    public List<DeliveryRouteTab> selectGoodPathList(DeliveryRouteTab deliveryRouteTab) {
        return goodPathMapper.selectGoodPathList(deliveryRouteTab);
    }

    @Override
    public void saveGoodPath(DeliveryRouteTab deliveryRouteTab) {
        deliveryRouteTab.setRowversion(new Date());
        String s = UUID.randomUUID().toString().replace("-", "").toUpperCase();
        String s1 = RandomStringUtils.randomNumeric(10);
        deliveryRouteTab.setRowkey(s+""+s1);
        goodPathMapper.saveGoodPath(deliveryRouteTab);
    }

    @Override
    public String checkRouteId(String routeId) {
        DeliveryRouteTab deliveryRouteTab= goodPathMapper.selectById(routeId);
        if(deliveryRouteTab!=null) {
            return "1";
        }
        return "0";
    }

    @Override
    public DeliveryRouteTab findGoodPath(String routeId) {
        DeliveryRouteTab deliveryRouteTab = goodPathMapper.selectById(routeId);
        return deliveryRouteTab;
    }

    @Override
    public void editSaveGoodPath(DeliveryRouteTab deliveryRouteTab) {
//        goodPathMapper.editSaveGoodPath(deliveryRouteTab);
        goodPathMapper.updateById(deliveryRouteTab);
    }

    @Override
    public int deleteGoodPathByIds(String[] ids) {
        int i=0;
        for (String id : ids) {
            int d = goodPathMapper.deleteById(id);
            i=i+d;
        }
        return i;
    }
}
